package com.ly.video.api.config.impl;

import com.ly.video.api.config.entity.DialogEntity;
import com.ly.video.api.config.mapper.DialogMapper;
import com.ly.video.api.config.service.IConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class ConfigServiceImpl implements IConfigService {

    @Autowired
    private DialogMapper dialogMapper;

    @Override
    public Integer addDialogInfo(String title, String content) {
        DialogEntity dialogEntity = new DialogEntity();
        dialogEntity.setTitle(title);
        dialogEntity.setContent(content);
        dialogEntity.setCreateTime(new Date());
        Integer i = dialogMapper.addDialogInfo(dialogEntity);
        return i;
    }

    @Override
    public DialogEntity getLastDialogInfo() {
        List<DialogEntity> lastDialogInfo = dialogMapper.getLastDialogInfo();
        if (lastDialogInfo.size() > 0) {
            return lastDialogInfo.get(0);
        }
        return null;
    }
}
